package listTest;

import java.util.ArrayList;

public class ListTest {
    public static void main(String[] args) {
        listDevice();
    }

    public static void listDevice() {
        //创建一个List里面只能存放Device类型
        ArrayList<Device> deviceList = new ArrayList<>();
        //创建一个Device类型的对象
        Device device = new Device();
        //设置device的id,name,userName
        device.setId(1L);
        device.setName("我的电脑");
        device.setUserName("谭婷婷");
        //往deviceList里面添加设备
        deviceList.add(device);
        Device device1 = new Device();
        device1.setId(2L);
        device1.setName("我的电脑2");
        device1.setUserName("谭婷婷2");
        deviceList.add(device1);
        //查看deviceList的元素个数
        int size = deviceList.size();
        System.out.println(size);
        System.out.println(deviceList.size());
        ArrayList<Device> deviceList2 = new ArrayList<>();

        for (int i = 0; i < deviceList.size(); i++) {
            Device device2 = deviceList.get(i);
            System.out.println("设备id: " + device2.getId() + ",设备name: " + device2.getName() + ",设备userName: " + device2.getUserName());
            //往deviceList2里添加设备,先get出来再添加
            deviceList2.add(deviceList.get(i));
        }
        System.out.println("==========================");
        System.out.println(deviceList2.size());
        for (Device d : deviceList2) {
            System.out.println("设备id: " + d.getId() + ",设备name: " + d.getName() + ",设备userName: " + d.getUserName());
        }
    }
}
